function dL = liklihoodFun_dL(q,path)


DEFAULT = 8;
NUM_RATE = 7;
% MIN_TIME_UNIT = 1/12; % 1 month in year measure



dL = sym('A%d%d',[8,8]);
dL(:,:) = 0;
for i = 1: length(path)
    temp = path(i).totalsRec;
    % check if the rating is same
    if temp(1,2)~= temp(1,3);
        % for cases with rating changes
        if isempty(find(temp == DEFAULT))
            % censoring situation
            length_temp = size(temp,1);
            for k = 1: length_temp
                
                if k ~= length_temp
                    dL= dL+ derivativeL(NUM_RATE,temp(k,1),temp(k,2), temp(k,3), q, 'normal');
                    
                else
                    % deal with censoring case
                    dL= dL+ derivativeL(NUM_RATE,temp(k,1),temp(k,2), temp(k,3), q, 'cencor');
                    
                end
            end
            
        else % default situation
            [ROW,COL] = find(temp ==DEFAULT);
            ROW_MIN = min(ROW);
            
            for k = 1: ROW_MIN
                if k ~= ROW_MIN
                    dL= dL+ derivativeL(NUM_RATE,temp(k,1),temp(k,2), temp(k,3), q, 'normal');
                    
                else
                    % deal with default case                                      
                    dL= dL+ derivativeL(NUM_RATE,temp(k,1),temp(k,2), temp(k,3), q, 'Default');
                end
                
            end
            
        end
        
    end
end

dL = double(dL);
end